$(window).load(function() {
  $('.flexslider').flexslider({
		directionNav: true,
		pauseOnAction: false
	});
   changeImage();

   $(window).resize(function(){
   	 changeImage();
   })
});

function changeImage(){
	var scrWidth = $(window).width();
	var scrHeight = $(".flexslider").height();
	$(".s-image").each(function(){
		var o = $(this);
		var imgWidth = o.width();
		var imgHeight = o.height();

		scr_b = scrWidth/scrHeight;
		img_b = imgWidth/imgHeight;

		if (scr_b > img_b){
			imgWidth = scrWidth;
	  		o.width(scrWidth);
	  		o.height("auto");
		}else{
			imgHeight = scrHeight;
	  		o.height(scrHeight);
	  		o.width("auto");
		}
		
	  	var _x = (scrWidth - o.width())/2;
	  	var _y = (scrHeight - o.height())/2;
	  	o.css({'left':_x,'top':_y});	  	
	})
}


$(document).ready(function() {
	//ajaxform
	var options = { 
		beforeSubmit:showRequest,//表单验证方式
        success:showResponse  // post-submit callback 
    }; 

    $('#ajaxForm').ajaxForm(options); 

    function showResponse(responseText, statusText)  {
		if (statusText == 'success') {
			var responseText=eval('('+responseText+')');
			if(responseText.state == 'SUCCESS'){
				$("#success").show();
				$("#subBox").hide();
			}else{
				$("#sign").removeAttr('disabled');
		 		$("#msg").html(responseText.state);	
			}			
		}else{
			$("#sign").removeAttr('disabled');
		 	$("#msg").html('Lost Service');			
		}
	} 

	function showRequest(){
		 validata = $("form.form-validata").valid();
		 if (validata){
		 	$("#sign").attr('disabled','disabled');
		 	$("#msg").html('<img src="/tpl/Home/common/image/loadding.gif">');
		 }
		 return validata;
	}

	//validation验证
	$("form.form-validata").validate({
		errorElement: "p",
        errorClass: "error",
	})
});